package pack0711.com;

import java.util.Scanner;

public class Menu {

    public static Scanner scan=new Scanner(System.in);

    //显示开始菜单
    public static void startMenu(){
        System.out.println("------------------------");
        System.out.println("-----欢迎使用自动取款机----");
        System.out.println("-------------------------");

        System.out.println("   1.注册   ");
        System.out.println("   2.登录   ");
        System.out.println("   3.管理员登录  ");
        System.out.println("   4.退出系统  ");

        int n=Tools.getN(1,4);  //传入两个参数
        switch (n){
            case 1:
            BankManager.register();
            break;
            case 2:
                User user=BankManager.login();
                if(user==null)
                    break;
                else{
                    //显示用户菜单
                    System.out.println("恭喜你,登陆成功");
                    userMenu(user);
                }
                break;
            case 3:
                boolean flag=BankManager.adminLogin();
                if(!flag){
                    System.out.println("管理员账号或者密码错误");
                    break;
                }else{
                    System.out.println("恭喜你,登陆成功");
                    //显示管理员菜单
                    adminMenu();
                }
                break;

            case 4:
                System.exit(1);  //停止虚拟机,1表示正常终止,0表示异常终止
                break;
        }
        startMenu();
    }

    private static void adminMenu() {
        System.out.println("当前用户:管理员");
        System.out.println("   1.查看所有用户  ");
        System.out.println("   2.冻结账户  ");
        System.out.println("   3.恢复账户  ");
        System.out.println("   4.查看冻结账户  ");
        System.out.println("   5.退出  ");

        boolean flag=false;
        while(true){
            int n=Tools.getN(1,5);

            switch (n){
                case 1:
                    BankManager.lookAllUserInfo();
                    break;
                case 2:
                    BankManager.froozeUser();
                    break;
                case 3:
                    BankManager.discoverUser();
                    break;
                case 4:
                    BankManager.lookFroozeUsers();
                    break;
                case 5:
                    flag=true;
                    break;
            }
            if(flag)
                break;
        }
        startMenu();
    }

    private static void userMenu(User user) {
        System.out.println("当前用户"+user.getName());
        System.out.println("   1.查看账户余额  ");
        System.out.println("   2.取钱  ");
        System.out.println("   3.存钱  ");
        System.out.println("   4.转账  ");
        System.out.println("   5.查看历史记录  ");
        System.out.println("   6.修改密码  ");
        System.out.println("   7.退出  ");

        boolean flag=false;

        while(true){
            int n=Tools.getN(1,7);

            switch(n){
                case 1:
                    BankManager.lookBalance(user);
                    break;
                case 2:
                    BankManager.getCash(user);
                    break;
                case 3:
                    BankManager.saveCash(user);
                    break;
                case 4:
                    BankManager.changeMoney(user);
                    break;
                case 5:
                    BankManager.lookHistory(user);
                    break;
                case 6:
                    BankManager.modifyPass(user);
                    break;
                case 7:
                    flag=true;
                    break;
            }
            if(flag)
                break;
        }
        startMenu();
    }
}
